Hint: Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
# load required libraries
# to use harry potter dataset
# devtools::install_github("bradleyboehmke/harrypotter")
# devtools::install_github("quanteda/quanteda.sentiment")
# devtools::install_github("quanteda/quanteda.corpora")
library(quanteda)
library(readtext)
library(corpus)
library(tidyverse)
library(stringr)
library(tidytext)
library(harrypotter)
library(janeaustenr)
library(dplyr)
library(quanteda.sentiment)
library(vader)
require(quanteda)
require(quanteda.corpora)
Lade nötiges Paket: quanteda.corpora
require(quanteda.sentiment)
# load afinn lexicon
# manually -> convert to binary lexicon
afinn_dict <- read.csv("lexika/AFINN-111.txt", header = F, sep = "\t", stringsAsFactors = F)
afinn_binary <- dictionary(list(positive = afinn_dict$V1[afinn_dict$V2>0], negative = afinn_dict$V1[afinn_dict$V2<0]))
# provided via tidytext?
afinn <- get_sentiments("afinn")
dfm.sentiment <- dfm(korpus, dictionary = afinn_binary)
Warnung: 'dfm.corpus()' is deprecated. Use 'tokens()' first.
Warnung: 'dictionary' and 'thesaurus' are deprecated; use dfm_lookup() instead
dfm.sentiment
Document-feature matrix of: 12 documents, 2 features (0.00% sparse) and 1 docvar.
features
docs positive negative
dal in 241 173
d-heade 211 153
of 180 155
scombe Valley 217 262
ve Ora 151 198
n with the Twi 195 225
[ reached max_ndoc ... 6 more documents ]